package com.hotel.web.controller.hotel;

import com.hotel.common.core.controller.BaseController;
import com.hotel.common.core.domain.AjaxResult;
import com.hotel.common.core.domain.entity.SysRole;
import com.hotel.common.core.page.TableDataInfo;
import com.hotel.system.domain.hotel.RoomType;
import com.hotel.system.service.RoomTypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 酒店房间信息操作处理
 * 
 * @author hotel
 */
@Controller
@RequestMapping("/hotel/roomType")
public class RoomTypeController extends BaseController
{
    private String prefix = "hotel/roomType/";

    @Autowired
    private RoomTypeService roomTypeService;

    @RequiresPermissions("hotel:roomType:view")
    @GetMapping()
    public String roomType()
    {

        return prefix + "roomType";
    }

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RoomType roomType)
    {
        startPage();
        List<RoomType> list = roomTypeService.selectRoomTypeList(roomType);
        return getDataTable(list);
    }

    @RequiresPermissions("hotel:roomType:add")
    @GetMapping("/add")
    public String addRoomType() {
        return prefix + "add";
    }

    @RequiresPermissions("hotel:roomType:add")
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@Validated RoomType RoomType) {

        return toAjax( roomTypeService.insertRoomType(RoomType));
    }

    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        mmap.put("roomType", roomTypeService.selectRoomTypeId(id));
        return prefix + "edit";
    }

    /**
     * 出库入库调整
     */
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editRoomType(@Validated RoomType roomType) {
        return toAjax(roomTypeService.updateRoomType(roomType));
    }

    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(roomTypeService.updateRoomTypeStatus(ids));
    }

    /**
     * 校验房间类型名称唯一
     * @param roomType
     * @return
     */
    @PostMapping("/checkRoomTypeNameUnique")
    @ResponseBody
    public boolean checkRoomTypeNameUnique(RoomType roomType)
    {
        return roomTypeService.checkRoomTypeNameUnique(roomType);
    }






}
